package fu.abc.controller;
import fu.abc.DAO.*;
import fu.abc.model.*;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class CreateLocation
 */
@WebServlet("/CreateLocation")
public class CreateLocation extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CreateLocation() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		
		Location location = new Location();
		LocationDAO localDAO = new LocationDAO();
		int status = 1;
		boolean mode = false;
		
		int idacc = Integer.parseInt( request.getParameter("account").trim());
		String localName = request.getParameter("localname").toString().trim();
		String category = request.getParameter("category").toString().trim();
		String province = request.getParameter("province").toString().trim();
		String addressDetail = request.getParameter("addresslocal").toString().trim();
		String phone = request.getParameter("phone").trim();
		String website = request.getParameter("website").trim();
		String descript = request.getParameter("descript").toString().trim();
//		String username = request.getParameter("acc").trim();
		
			location.setLocationName(localName);
			location.setCategory(category);
			location.setProvince(province);
			location.setAddressDetail(addressDetail);
			location.setPhone(phone);
			location.setWebsite(website);
			location.setDescript(descript);
			location.setStatus(status);
			location.setMode(mode);
			location.setIdacc(idacc);
			
			try {
				localDAO.createLocation(location);
				response.sendRedirect("/Vnplace/content-editor/manageLocation.jsp");
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
	}

}
